#include "EventPoller.h"
#include "Game.h"
#include "GUIManager.h"
#include "SplashState.h"
#include "SoundManager.h"
#include "TutorialState.h"

void TutorialState::LoadImages()
{
	//THE BACKGROUND IMAGE
	m_bkgroundImg.SetTexPath("Textures/Tutorial Screen.png");
	m_bkgroundImg.SetPos(Vec2f(0.0f, 0.0f));
	m_bkgroundImg.SetDims(Vec2f(2.0f, 2.0f));
	m_bkgroundImg.SetActivate(true);
}

void TutorialState::LoadButtons()
{
	//THE BACK BUTTON
	m_backButt.SetTexPath("Textures/Back.png");
	m_backButt.SetPos(Vec2f(1.4f, 0.2f));
	m_backButt.SetDims(Vec2f(0.35f, 0.2f));
	m_backButt.SetActivate(true);
}

void TutorialState::OnActivated()
{
	TheEventPoller::Instance()->AddHandler(this);

	//THE CUSTOM CURSOR
	m_custCursor.SetDims(Vec2f(0.1f, 0.1f));
	m_custCursor.SetActivate(true);

	//THE IMAGES
	LoadImages();

	//THE BUTTONS
	LoadButtons();
}

void TutorialState::OnDeactivated()
{
	TheEventPoller::Instance()->RemoveHandler(this);

	m_bkgroundImg.SetActivate(false);
	m_custCursor.SetActivate(false);
	m_backButt.SetActivate(false);
}

void TutorialState::Draw()
{
	glClearColor(1,1,1,1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	TheGUIManager::Instance()->Draw();
}

void TutorialState::Update()
{
	TheGUIManager::Instance()->Update();

	m_backButt.SetPressed(false);
}

void TutorialState::OnKeyboardEvent(const SDL_KeyboardEvent& k)
{
	if(k.keysym.sym == SDLK_ESCAPE && k.state == SDL_PRESSED)
	{
		exit(0);
	}
}

void TutorialState::OnMouseButtonDownEvent(const SDL_MouseButtonEvent& mb)
{
	m_backButt.OnMouseButtonDownEvent(mb);

	if(mb.button == SDL_BUTTON_LEFT)
	{
		if(mb.state == SDL_PRESSED)
		{
			if (m_backButt.GetPressed())
			{
				TheGame::Instance()->SetGameState(TheSplashState::Instance());
			}
		}
	}
}

void TutorialState::OnMouseMotionEvent(const SDL_MouseMotionEvent& mm)
{
	m_custCursor.OnMouseMotionEvent(mm);
	m_backButt.OnMouseMotionEvent(mm);

	if (m_backButt.GetOver())
	{
		m_backButt.SetTexPath("Textures/Back Glow.png");
	}
	else
	{
		m_backButt.SetTexPath("Textures/Back.png");
	}
}